package com.zc.study.thread.多线程第六章节.thread6_1_2;

public class Service {
    private volatile  static Service service;
    //使用双重检查锁机制,既保证了不需要同步代码的异步执行性,又保证了单例效果
    private  Service() {
    }

    synchronized public static Service getInstance() {
        if (service ==null){
            synchronized (Service.class){
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            service = new Service();

            }
        }
        return service;
    }
}
